//
//  ChooseCompetitorCell.m
//  YunGui
//
//  Created by Hanen 3G 01 on 16/4/15.
//  Copyright © 2016年 hanen. All rights reserved.
//

#import "ChooseCompetitorCell.h"
#import "SettingButton.h"


@implementation ChooseCompetitorCell
+ (instancetype)cellWithTabelView:(UITableView *)tableView
{
    static NSString *celId = @"ChooseCompetitorCellID";
    ChooseCompetitorCell *cell = [tableView dequeueReusableCellWithIdentifier:celId];
    
    if (!cell) {
        cell = [[ChooseCompetitorCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:celId];
      [cell addSubviews];
    }
 
    return cell;
}
- (void)addSubviews
{
//    UIView *backgroundView = [[UIView alloc] initWithFrame:self.contentView.bounds];
//    backgroundView.backgroundColor = [UIColor clearColor];
//    self.backgroundView = backgroundView;
    
//    for (SettingButton *v in self.subviews) {
//        [v removeFromSuperview];
//    }
    
    self.settingBtn = [[CompetitorButton alloc] initWithFrame:CGRectMake([UIView getWidth:20.0f], 0, kScreenWidth, [ChooseCompetitorCell cellHeight] )];
    [self.settingBtn setTitleColor:BLACKCOLOR forState:UIControlStateNormal];
    self.settingBtn.titleLabel.font = [ViewTool getFont:16.0f];
    self.settingBtn.imageEdgeInsets = UIEdgeInsetsMake([UIView getWidth:25.0f], 0, 0, 0);
//    self.settingBtn.imageView.layer.cornerRadius = 15 / 2.0f ;
//    self.settingBtn.imageView.layer.masksToBounds = YES;
//    self.settingBtn.imageView.layer.shouldRasterize = YES;
    [self.settingBtn setImage:[UIImage imageNamed:@"noselected1"] forState:UIControlStateNormal];
//    [self.settingBtn setBackgroundColor:[UIColor redColor]];
//    [self.settingBtn setImage:[ViewTool getImageFromColor:BlueColor WithRect:CGRectMake(0, 0, 15, 15)] forState:UIControlStateSelected];
    self.settingBtn.isSelected = NO;
    [self.settingBtn addTarget:self action:@selector(handleSelect:) forControlEvents:UIControlEventTouchUpInside];
//    self.settingBtn.enabled = NO;
    [self.contentView addSubview:self.settingBtn];
    
    UIView  *line = [ViewTool getLineViewWith:CGRectMake([UIView getWidth:20.0f] +25, [ChooseCompetitorCell cellHeight] - 1, kScreenWidth -[UIView getWidth:20.0f], 1) withBackgroudColor:GRAYLINECOLOR];
    [self.contentView addSubview:line];
//    self.contentView.backgroundColor =[UIColor cyanColor];
//    self.backgroundView.backgroundColor = [UIColor orangeColor];
}

- (void)handleSelect:(CompetitorButton *)sender
{
    if (sender.isSelected == NO) {
//        [sender setImage:[ViewTool getImageFromColor:BlueColor WithRect:CGRectMake(0, 0, 15, 15)] forState:UIControlStateNormal];

        [sender setImage:[UIImage imageNamed:@"Btn_Normal_dui"] forState:UIControlStateNormal];
//      sender.isSelected = YES;
    }else{
//        [sender setImage:[ViewTool getImageFromColor:[UIColor whiteColor] WithRect:CGRectMake(0, 0, 15, 15)] forState:UIControlStateNormal];

        [sender setImage:[UIImage imageNamed:@"noselected1"] forState:UIControlStateNormal];
//         sender.isSelected = NO;
    }
    sender.isSelected = !sender.isSelected;
//    NSLog(@"按钮 是否选择%d", self.settingBtn.selected);
//    if (self.selectedBlcok) {
        _selectedBlcok( sender.isSelected , _row);
//    }
}
- (void)setDataDict:(NSDictionary *)dataDict
{
    _dataDict = dataDict;
    [self.settingBtn setTitle:dataDict[@"name"] forState:UIControlStateNormal];
    
}
+ (CGFloat)cellHeight
{
    return 44.0f;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
